﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace XNA_TD
{
    public class Wasser : IRunable, IDraw
    {
        Texture2D texture;
        VertexPositionTexture[] vertices;

        public Wasser()
            : base(Priority.Logic)
        {
            texture = new Texture2D(graphics.GraphicsDevice, 1, 1);
            texture.SetData(new Color[] { new Color(0,0,255,100) });

            vertices = new VertexPositionTexture[6];

            Vector3 bottomLeft = new Vector3(0, 0, 0);
            Vector3 bottomRight = new Vector3(terrain.terrainWidth, 0, 0);
            Vector3 topLeft = new Vector3(0, 0, terrain.terrainHeight);
            Vector3 topRight = new Vector3(terrain.terrainWidth, 0, terrain.terrainHeight);

            int i = 0;
            vertices[i++] = new VertexPositionTexture(topRight, new Vector2(1, 1));
            vertices[i++] = new VertexPositionTexture(bottomLeft, new Vector2(0, 0));
            vertices[i++] = new VertexPositionTexture(bottomRight, new Vector2(1, 0));

            vertices[i++] = new VertexPositionTexture(topRight, new Vector2(1, 1));
            vertices[i++] = new VertexPositionTexture(bottomLeft, new Vector2(0, 0));
            vertices[i++] = new VertexPositionTexture(topLeft, new Vector2(0, 1));
        }

        public void Draw()
        {
            shader.CurrentTechnique = shader.Techniques["Water"];
            shader.Parameters["World"].SetValue(Matrix.CreateTranslation(-.5f, 0, -.5f));
            shader.Parameters["Texture1"].SetValue(texture);

            foreach (EffectPass pass in shader.CurrentTechnique.Passes)
            {
                pass.Apply();
                graphics.GraphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, vertices, 0, 2);
            }
        }

        public override void Load()
        {
        }

        public override void UnLoad()
        {
        }
    }
}
